package com.k2.whereareyou.engine;

import java.io.File;

import com.k2.whereareyou.R;
import com.k2.whereareyou.xml.PhotoXMLAnsver;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class DataAdapterPhoto extends BaseAdapter{
	
	private Activity activity;
	private PhotoXMLAnsver[] photoList;  
    private static LayoutInflater inflater = null;  
	
   
    
    public DataAdapterPhoto(Activity a, PhotoXMLAnsver[] photoList) {
        activity = a;
        inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        this.photoList = photoList;
    }
    
   
        
    public View getView(int position, View convertView, ViewGroup parent) {
    	View vi=convertView;
    	if(convertView==null)
            vi = inflater.inflate(R.layout.item_photo, null);
 
        TextView nick = (TextView)vi.findViewById(R.id.TextView_nick_item_photo); 
        TextView date = (TextView)vi.findViewById(R.id.TextView_date_koord_item_photo); 
        ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); 
  
        nick.setText(photoList[position].getNick());
        date.setText(photoList[position].getData() + photoList[position].getKoord() + photoList[position].getId());
        
        BitmapFactory.Options options = new BitmapFactory.Options();
		options.inSampleSize = 2;

		File sdPath = Environment.getExternalStorageDirectory();
		final Bitmap bitmap = BitmapFactory.decodeFile(sdPath.getAbsolutePath() + "/Where_are_you/cache/" +photoList[position].getId() + "_mini.jpg", null);
		thumb_image.setImageBitmap(bitmap);
        return vi;
        }


	@Override
	public int getCount() {
		return photoList.length;
	}

	@Override
	public Object getItem(int position) {
		return position;
	}

	@Override
	public long getItemId(int position) {
		return position;
	}
}
